package com.yazdankhah.beans;

import com.yazdankhah.utils.DataTools;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;

/**
 *
 * @author ahmad
 */
@ManagedBean(name = "bean")
@SessionScoped
public class Bean implements Serializable {
  
  private int chapter = 1;
  private int verse = 2;
  private int serial = 2;
  
  private Combo combo;
  

  public Bean() {
    
    combo = DataTools.lookupQuran(chapter, verse);
    
  } //constructor
  
  public String lookupVerse(AjaxBehaviorEvent event) {
    
//    System.out.println("chapter = [" + chapter + "]");
//    System.out.println("verse = [" + verse + "]");
    
//    int chapterInt = chapter == null ? 0 : Integer.valueOf(chapter);
//    int verseInt = chapter == null ? 0 : Integer.valueOf(verse);
    
    serial = DataTools.getSerial(chapter, verse);
    combo = DataTools.lookupQuran(serial);
    
    //System.out.println("quranVerse = [" + quranVerse + "]");
    
    return null;
  } //method


  public String lookupNextVerse(AjaxBehaviorEvent event) {
    
    serial++;
    VerseAddr verseAddr = DataTools.getVerseAddr(serial);
    combo = DataTools.lookupQuran(serial);
    
    chapter = verseAddr.getChapter();
    verse = verseAddr.getVerse();
    
    return null;
  } //method


  public String lookupPereviousVerse(AjaxBehaviorEvent event) {
    
    serial--;
    VerseAddr verseAddr = DataTools.getVerseAddr(serial);
    combo = DataTools.lookupQuran(serial);
    
    chapter = verseAddr.getChapter();
    verse = verseAddr.getVerse();
    
    return null;
  } //method


  public int getChapter() {
    return chapter;
  }


  public void setChapter(int chapter) {
    this.chapter = chapter;
  }


  public int getVerse() {
    return verse;
  }


  public void setVerse(int verse) {
    this.verse = verse;
  }


  public int getSerial() {
    return serial;
  }


  public void setSerial(int serial) {
    this.serial = serial;
  }


  public Combo getCombo() {
    return combo;
  }


  public void setCombo(Combo combo) {
    this.combo = combo;
  }
  
} //method
